//
//  OtherViewController.m
//  Fantasia
//
//  Created by kongkong on 2016/12/4.
//  Copyright © 2016年 Kongkong. All rights reserved.
//

#import "OtherViewController.h"
#import "TopupViewController.h"
#import "AlertViewController.h"


@interface OtherViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong) UITableView*   tableView;
@property (nonatomic,strong) NSArray*   data;
@end

@implementation OtherViewController

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidLoad{
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    
    [self setupTitle];
    
    self.data = @[@"充值操作",@"报警记录",@"消费记录"];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setupTitle];
}

- (void)setupTitle{
    NSString* title = [[FantasiaStorage instance]memoryValueForKey:@"currentDevice"];
    self.tabBarController.title =[title stringByAppendingString:@" 操作"];
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

#pragma -mark
#pragma -mark UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.data.count;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = self.data[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
        case 0:
            [[UIViewController rootNavigationController] pushViewController:[[TopupViewController alloc] init] animated:YES];
            break;
        case 1:
            [[UIViewController rootNavigationController] pushViewController:[[AlertViewController alloc]init] animated:YES];
            break;
        case 2:
            break;
        default:
            break;
    }
}
@end
